﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using TodoList.ViewModel;
using TodoList.Mode;
using System.Xml.Linq;
using TodoList.Common;


namespace TodoList
{
    class SaveCommand : ICommand
    {
        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            TodoVM todoVm = parameter as TodoVM;
            Todo todoAdd = todoVm.Todo;
            List<Todo> todoList = Utils.GetTodoList(todoVm.FileName);
            todoList.Add(todoAdd);            
            Utils.SaveTodoItem(todoVm.FileName, todoList);
            todoVm.TodoList = todoList;
            todoVm.LoadAction.Execute(parameter);
            Console.WriteLine("Save clicked");
        }

       

        #endregion
    }
}
